#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=55,mo=10000007;
int n;
char ch[1005][N],S[N];
bool pd[1005];
template<typename T>void read(T &ss)
{
	char ch;ss=0;ch=getchar();
	for (;!isdigit(ch);ch=getchar());
	for (;isdigit(ch);ch=getchar()) ss=(ss<<1)+(ss<<3)+(ch^48);
	return;
}
bool bj(int i,int j)
{
	if (strlen(ch[i]+1)!=strlen(ch[j]+1)) return 1;
	for (int k=1;k<=strlen(ch[i]+1);k++)
	{
		if (ch[i][k]!=ch[j][k]) return 1;
	}
	return 0;
}
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	read(n);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",S+1);
		if (S[1]=='S')
		{
			pd[i]=0;
			scanf("%s",ch[i]+1);
			bool bz=0;int s=0,a1=0,a2=0;
			for (int j=1;j<=strlen(ch[i]+1);j++)
			{
				if (ch[i][j]=='.'||ch[i][j]==':') 
				{
					if (ch[i][j]=='.')
					{
						a1++;
						if (a1>3){bz=1;break;}
						if (a2){bz=1;break;}
					} 
					if (ch[i][j]==':')
					{
						if (a1!=3){bz=1;break;}
						a2++;
						if (a2>1){bz=1;break;}
					 }
					if (s>255){bz=1;break;}s=0;
				}
				else 
				{
					s=(s<<1)+(s<<3)+(ch[i][j]^48);
					if ((ch[i][j+1]>='0'&&ch[i][j+1]<='9')&&ch[i][j]=='0'&&(ch[i][j-1]==':'||ch[i][j-1]=='.')){bz=1;break;}
				}
			}
			
			if (a1!=3) bz=1;if (a2!=1) bz=1;
			if (s>65535) bz=1;
			if (bz) printf("ERR\n");
			else
			{
				for (int j=1;j<i;j++)
					if (!bj(i,j)&&pd[j]==0){bz=1;break;}
				if (bz) printf("FAIL\n");
				else printf("OK\n");
			}
		}
		else
		{
			pd[i]=1;
			scanf("%s",ch[i]+1);
			int bz=0;int s=0,a2=0,a1=0;
			for (int j=1;j<=strlen(ch[i]+1);j++)
			{
				if (ch[i][j]=='.'||ch[i][j]==':') 
				{
					if (ch[i][j]=='.')
					{
						a1++;
						if (a1>3){bz=1;break;}
						if (a2){bz=1;break;}
					} 
					if (ch[i][j]==':')
					{
						if (a1!=3){bz=1;break;}
						a2++;
						if (a2>1){bz=1;break;}
					 }
					if (s>255){bz=1;break;}
					s=0;
				}
				else
				{
					s=(s<<1)+(s<<3)+(ch[i][j]^48);
				if ((ch[i][j+1]>='0'&&ch[i][j+1]<='9')&&ch[i][j]=='0'&&(ch[i][j-1]==':'||ch[i][j-1]=='.')){bz=1;break;}
				}
				
			}
			if (a1!=3) bz=1;if (a2!=1) bz=1;
			if (s>65535) bz=1;
			if (bz) printf("ERR\n");
			else
			{
				bz=0;
				for (int j=1;j<i;j++)
					if (!bj(i,j)&&pd[j]==0){bz=j;break;}
				if (!bz) printf("FAIL\n");
				else printf("%d\n",bz);
			}
		}
	}
}

